package cn.itcast.bos.web.action.base;

import java.io.File;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;


import cn.itcast.bos.domain.base.Area;
import cn.itcast.bos.service.base.AreaService;
import cn.itcast.bos.web.action.common.BaseAction;

@Namespace("/")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class AreaAction extends BaseAction<Area>{

	
	@Autowired
	private AreaService areaService;

	//查询区域
	@Action(value="area_search",results={@Result(name="success",type="json")})
	public String searchArea() {
		Pageable pageable = new PageRequest(page-1, rows);
		
		Page<Area> pageData = areaService.searchArea(model,pageable);
		
		pushPageDataToValueStack(pageData);
		return SUCCESS;
	}
	
	private File file;

	public void setFile(File file) {
		this.file = file;
	}
	
	private String fileFileName;
	
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}


	//解析exl导入地区
	@Action(value="area_batchImport")
	public String batchImport() throws Exception {
		
		System.out.println(fileFileName);
		
		areaService.saveBatch(file,fileFileName);
		System.out.println("读取并添加成功");
		return NONE;
	}
}
